#!/bin/python3
# -*- coding:utf-8 -*-
"""
    [模块名]
    Add By :陈狍子 e4ting@qq.com 2024-05-25 14:01:48
"""

from flask_restful          import Resource
from flask                  import redirect,request,make_response

from e4ting                 import util,log
# from common.utilredis       import NewID
from e4ting.cache           import UUIDCache, OnlineCache
from models.mongos          import DB
# from e4ting.task            import Async
# from bin.master             import Master
import io


class WebYamlFormat(Resource):

    def post(self, id=None):
        """ 格式化yaml文件 """
        from ruamel.yaml import YAML
        yaml = YAML(typ=['rt', 'rt'])
        # yaml.preserve_quotes = True
        # yaml.indent(sequence=4, offset=2)  # 设置缩进为4个空格
        yaml_str = request.json.get("text", None)
        # log.info(f"\n{yaml_str}")
        data = yaml.load(yaml_str)
        out = io.StringIO()
        yaml.indent(mapping=4, sequence=1, offset=4)
        yaml.dump(data, out)
        output = out.getvalue()
        log.info(f"\n{output}")
        return dict(code=200, data=output)

